package baseclass.a_sort;


import baseclass.a_sort.bucketSort.BucketSort;
import baseclass.h_heap.HeapSort;

import java.util.Arrays;

/**
 * @Author: lizhen
 * @Date: 2019/9/2 0002 下午 6:11
 * @Version: 1.0
 * @desc: 对数器
 **/
public class Generator {


    public static void swap(int[] arr, int i, int j) {
        if (i == j) return;
        arr[i] = arr[i] ^ arr[j];
        arr[j] = arr[i] ^ arr[j];
        arr[i] = arr[i] ^ arr[j];
    }

    // for test
    public static void comparator(int[] arr) {
        Arrays.sort(arr);
    }

    // for test
    public static int[] generateRandomArray(int maxSize, int maxValue) {
        //产生 [0-maxsize]随机长度的数组
        int[] arr = new int[(int) ((maxSize + 1) * Math.random())];
        for (int i = 0; i < arr.length; i++) {
            //随机产生数据
            arr[i] = (int) ((maxValue + 1) * Math.random()) - (int) (maxValue * Math.random());
        }
        return arr;
    }

    // for test
    public static int[] copyArray(int[] arr) {
        return Arrays.copyOf(arr, arr.length);
    }

    // for test
    public static boolean isEqual(int[] arr1, int[] arr2) {
        if (arr1 == null && arr2 == null) {
            return true;
        }
        if (arr1 == null || arr2 == null) {
            return false;
        }
        if (arr1.length != arr2.length) {
            return false;
        }
        for (int i = 0; i < arr1.length; i++) {
            if (arr1[i] != arr2[i]) {
                return false;
            }
        }
        return true;
    }

    // for test
    public static void printArray(int[] arr) {
        System.out.println(Arrays.toString(arr));
    }

    // for test
    public static void main(String[] args) {
        int testTime = 500000;
        int maxSize = 10;
        int maxValue = 10;
        boolean succeed = true;
        int[] arr = null;
        for (int i = 0; i < testTime; i++) {
            int[] arr1 = generateRandomArray(maxSize, maxValue);
            int[] arr2 = Arrays.copyOf(arr1,arr1.length);
            arr = Arrays.copyOf(arr1,arr1.length);
            BucketSort.bucketSort(arr1);
//            Demo.mergeSort(arr2);
            HeapSort.heapSort(arr2);
//            comparator(arr2);
//            if(SmallNum_小数和.solution(arr1) != SmallNum_小数和.getSmallSum(arr2)){
            if (!isEqual(arr1, arr2)) {
                succeed = false;
                printArray(arr);
                break;
            }
        }
        System.out.println(succeed ? "Nice!" : "Fucking fucked!");


    }
}
